/**
 * @file skoll.config.js
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: skoll.config.js 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/skins/Skoll/js/skoll.config.js $
 */

Skoll.configLeechesRun = function() {
	if (Skoll.config.loaded) {
		Skoll.configLeeches.forEach(function(func) {
			if (typeof func == "function") {
				func();
			}

			Skoll.configLeeches.splice(Skoll.configLeeches.indexOf(func), 1);
		});
	} else if (!Skoll._configLeechesRunning) {
		Skoll._configLeechesRunning = true;
		setTimeout(function() {
			Skoll._configLeechesRunning = false;
			Skoll.configLeechesRun();
		}, 100);
	}
};
Skoll._configLeechesRunning = false;

$("script[src*='js/skoll.full.js'],script[src*='js/skoll.min.js']").on("load", function() {
	$.ajax({
		dataType: "json",
		url: $(this).attr("src").dirname().dirname() + "/config.json",
		success: function(data) {
			Skoll.config = data;
			Skoll.config.loaded = true;
			Skoll.configLeechesRun();
		},
		error: function(data) {
			Skoll.config.loaded = true;
			Skoll.tools.log("Skoll seems to have no configuration");
		}
	});
});

$(document).ready(function() {
	Skoll.configLeechesRun();
});